{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print(i)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "3\n",
      "6\n",
      "10\n",
      "15\n",
      "21\n",
      "28\n",
      "36\n",
      "45\n"
     ]
    }
   ],
   "source": [
    "n=1\n",
    "sum=0\n",
    "while n<10:\n",
    "    sum+=n\n",
    "    print(sum)\n",
    "    n+=1"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "登录成功\n"
     ]
    }
   ],
   "source": [
    "T_password='123456'\n",
    "p=''\n",
    "while p!=T_password:\n",
    "    p=input('请输入密码：')\n",
    "print('登录成功')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "14\n",
      "17\n",
      "21\n",
      "27\n",
      "28\n",
      "35\n",
      "37\n",
      "42\n",
      "47\n",
      "49\n",
      "56\n",
      "57\n",
      "63\n",
      "67\n",
      "70\n",
      "71\n",
      "72\n",
      "73\n",
      "74\n",
      "75\n",
      "76\n",
      "77\n",
      "78\n",
      "79\n",
      "84\n",
      "87\n",
      "91\n",
      "97\n",
      "98\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,101):\n",
    "    if i%7==0 or '7' in str(i):\n",
    "        print(i)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h 104\n",
      "e 101\n",
      "l 108\n",
      "l 108\n",
      "o 111\n",
      "  32\n",
      "w 119\n",
      "o 111\n",
      "r 114\n",
      "l 108\n",
      "d 100\n"
     ]
    }
   ],
   "source": [
    "msg = 'hello world'\n",
    "for c in msg:\n",
    "    print(c,ord(c))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aadd\n"
     ]
    }
   ],
   "source": [
    "print('sadawdsd'[1:9:2])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "print(random.randint(1, 100))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------\n",
      "你的值为5,机器人的值为4\n",
      "你的值为4,机器人的值为5\n",
      "你的值为3,机器人的值为4\n",
      "你输了\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "# 骰子游戏三局两胜\n",
    "print('----------')\n",
    "player_win=0\n",
    "bot_win=0\n",
    "for i in range(3):\n",
    "    player = int(input('请输入一个1-6的整数：'))\n",
    "    while player not in range(1,6):\n",
    "\n",
    "        player=int(input('重新输入1-6的整数'))\n",
    "    bot = random.randint(1,6)\n",
    "    print(f'你的值为{player},机器人的值为{bot}')\n",
    "    if player==bot:\n",
    "        pass\n",
    "\n",
    "    elif player>bot:\n",
    "        player_win+=1\n",
    "\n",
    "    else:\n",
    "         bot_win+=1\n",
    "\n",
    "if player_win>bot_win:\n",
    "    print('你赢了')\n",
    "else:\n",
    "    print('你输了')\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1   \n",
      "1*2=2   2*2=4   \n",
      "1*3=3   2*3=6   3*3=9   \n",
      "1*4=4   2*4=8   3*4=12  4*4=16  \n",
      "1*5=5   2*5=10  3*5=15  4*5=20  5*5=25  \n",
      "1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36  \n",
      "1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49  \n",
      "1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64  \n",
      "1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81  \n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for j in range(1,i+1):\n",
    "        print(f'{j}*{i}={i*j}'.ljust(7),end=' ')\n",
    "    print()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1636334098352\n",
      "1636334098352\n"
     ]
    }
   ],
   "source": [
    "a='123'\n",
    "b='123'\n",
    "print(id(a))\n",
    "print(id(b))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "show: ABC\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "m = 10\n",
    "def show():\n",
    "    # 局部变量与全局变量同名\n",
    "    m = \"ABC\"\n",
    "    # 使用局部变量\n",
    "    print(\"show:\", m)\n",
    "\n",
    "# 使用全局变量\n",
    "print(m)\n",
    "show()\n",
    "# 使用全局变量\n",
    "print(m)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}